using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using WPCoco.Helpers;
using WPCoco.Particles.Codecs;

namespace WPCoco.Particles
{
    public partial class ParticleSystem
    {
        static ParticleSystem()
        {
            types = ReflectionHelper.TypesForInterface(typeof(IParticleSystemReader));
        }

        static Type[] types;

        public static ParticleSystem LoadFromFile(string assetName) 
        {
            XDocument doc = XDocument.Load("Content/" + assetName + ".xml");
            if (doc == null) return null;
            IParticleSystemReader reader;
            ParticleSystem system = null;
            foreach (var t in types)
            {
                reader = Activator.CreateInstance(t) as IParticleSystemReader;
                system = reader.Read(doc);
                if (system != null) break;
            }
            return system;
        }
    }
}
